package com.amigo.online.provider.sync.handle.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.provider.sync.handle.data.redis.service.UserRedisService;
import com.amigo.online.provider.sync.handle.service.AbstractDataHandler;
import com.amigo.online.provider.sync.handle.service.DataHandler;

@Service("userRedisDataHandler")
@SuppressWarnings({"rawtypes"})
public class UserRedisDataHandler extends AbstractDataHandler implements DataHandler {

    @Autowired
    @Qualifier("userRedisTemplate")
    RedisTemplate userRedisTemplate;

    private static List<String> USER_UPDATE_COL;

    @Value("${redis_user_update_col}")
    public void setUserUpdateCol(String userUpdateCol) {
        USER_UPDATE_COL = Arrays.asList(userUpdateCol.split(","));
    }

    @Autowired
    UserRedisService userRedisService;

    /**
     * 存在对应数据修改删除对应对象即可
     */
    @Override
    public void updateHandle(JSONObject newObject, JSONObject oldObjecet) {
        long id = newObject.getLongValue("id");
        long result = 0;
        for (String temp : oldObjecet.keySet()) {
            if (USER_UPDATE_COL.contains(temp)) {
                result = userRedisService.deleteObject(id);
                if (result == 0) {
                    logger.error("更新mongoUser表数据失败！更新数据ID: " + id);
                    //kafkaMessageSender.FailLogSend("", "");
                }
                break;
            }
        }


    }

    /**
     * 暂不做任何处理
     */
    @Override
    public void insertHandle(JSONObject newObject) {

    }

    @Override
    public void updateInfoByIdThroughHashMap(Long id, Map<String, Object> updateMap) {
        //  Auto-generated method stub

    }

    @Override
    public void insertObject(Object source) {
        //  Auto-generated method stub

    }

}
